
/**
 * 本模块用于管理sceneId和{liveId,javaClient,dyClient}的映射表
 */

const sceneMap = new Map();

/**
 * 建立sceneId和{liveId,javaClient,dyClient}关联
 */
function addClient({
    sceneId,
    liveId,
    javaClient,
    dyClient
}) {
  if(!sceneId) {
    throw new Error("Missing sceneId");
  }
  let client = sceneMap.get(sceneId);
  if(!client) {
    client = {
      liveId: null,
      javaClient: null,
      dyClient: null
    };
  }
  if(liveId) {
    client.liveId = liveId;
  }
  if(javaClient) {
    client.javaClient = javaClient;
  }
  if(dyClient) {
    client.dyClient = dyClient;
  }
  sceneMap.set(sceneId, client);
}

/**
 * 根据sceneId获取客户端
 */
function getClient(sceneId) {
  console.log(sceneMap);
  let client = sceneMap.get(sceneId);
  if(!client) {
    return null;
  }
  return client;
}

/**
 * 根据sceneId移除客户端
 */
function removeClient(sceneId) {
  sceneMap.delete(sceneId);
}

module.exports = {
  addClient,
  getClient,
  removeClient
};